package com.ruoyi.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.employer.domain.CargoSourceDetails;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.driver.domain.CarownerCardetials;
import com.ruoyi.driver.service.ICarownerCardetialsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆详情Controller
 * 
 * @author Wevon
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/driver/cardetials")
public class CarownerCardetialsController extends BaseController
{
    @Autowired
    private ICarownerCardetialsService carownerCardetialsService;

    /**
     * 查询车辆详情列表
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerCardetials carownerCardetials)
    {
        startPage();
        List<CarownerCardetials> list = carownerCardetialsService.selectCarownerCardetialsList(carownerCardetials);
        return getDataTable(list);
    }

    /**
     * 查询车辆详情列表(不分页)
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:list')")
    @GetMapping("/listAll")
    public TableDataInfo list()
    {
        List<CarownerCardetials> list = carownerCardetialsService.selectCarownerCardetialsList(null);
        return getDataTable(list);
    }

    /**
     * 查询车辆详情列表(根据货源信息)
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:list')")
    @GetMapping("/listAllBySource")
    public TableDataInfo listAll(CargoSourceDetails cargoSourceDetails)
    {
        List<CarownerCardetials> list = carownerCardetialsService.selectCarDetailsByCargoSource(cargoSourceDetails);
        return getDataTable(list);
    }

    /**
     * 导出车辆详情列表
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:export')")
    @Log(title = "车辆详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerCardetials carownerCardetials)
    {
        List<CarownerCardetials> list = carownerCardetialsService.selectCarownerCardetialsList(carownerCardetials);
        ExcelUtil<CarownerCardetials> util = new ExcelUtil<CarownerCardetials>(CarownerCardetials.class);
        util.exportExcel(response, list, "车辆详情数据");
    }

    /**
     * 获取车辆详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carownerCardetialsService.selectCarownerCardetialsById(id));
    }

    /*根据车主ID获取车辆详情信息*/
    @GetMapping("/byCarOwnerId/{carOwnerId}")
    public AjaxResult selectByCarOwnerId(@PathVariable("carOwnerId") Long carOwnerId){
        return success(carownerCardetialsService.selectCardetialsByCarOwnerID(carOwnerId));
    }

    /**
     * 新增车辆详情
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:add')")
    @Log(title = "车辆详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerCardetials carownerCardetials)
    {
        return toAjax(carownerCardetialsService.insertCarownerCardetials(carownerCardetials));
    }

    /**
     * 修改车辆详情
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:edit')")
    @Log(title = "车辆详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerCardetials carownerCardetials)
    {
        return toAjax(carownerCardetialsService.updateCarownerCardetials(carownerCardetials));
    }

    /**
     * 删除车辆详情
     */
    @PreAuthorize("@ss.hasPermi('driver:cardetials:remove')")
    @Log(title = "车辆详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carownerCardetialsService.deleteCarownerCardetialsByIds(ids));
    }
}
